# Contributor: Dennis Krupenik <dennis@krupenik.com>
# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=spirv-llvm-translator
_pkgname=SPIRV-LLVM-Translator
pkgver=19.1.0
pkgrel=0
pkgdesc="Library for bi-directional translation between SPIR-V and LLVM IR"
url="https://github.com/KhronosGroup/SPIRV-LLVM-Translator"
arch="all"
license="NCSA"
_llvmver=${pkgver%%.*}
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	llvm$_llvmver-dev
	spirv-tools-dev
	"
makedepends="
	$depends_dev
	clang$_llvmver
	cmake
	libxml2-dev
	llvm$_llvmver-static
	llvm$_llvmver-gtest
	samurai
	"
checkdepends="llvm$_llvmver-test-utils"
subpackages="$pkgname-dev $pkgname-libs"
source="https://github.com/KhronosGroup/SPIRV-LLVM-Translator/archive/v$pkgver/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
options="!check" # invalid files passed to lit?

case "$CARCH" in
x86_64) ;;
# Failing tests
*) options="!check";;
esac

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		cmake_crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CC=clang \
	CXX=clang++ \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DLLVM_SPIRV_INCLUDE_TESTS=1 \
		-DLLVM_EXTERNAL_LIT=/usr/lib/llvm$_llvmver/bin/lit \
		-DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=/usr/include/spirv \
		$cmake_crossopts
	cmake --build build
}

check() {
	ctest --test-dir build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
646e8d812390550469aa1f0f27c9a2af09a9c16f1e2a7ec3a952be88973f70eda5dae54251f0cfe955802b97579185d964d947c2ccc41e8e6c7a1a95908f0c42  SPIRV-LLVM-Translator-19.1.0.tar.gz
"
